package com.building18.mapper;

import com.building18.pojo.User;
import com.building18.pojo.dto.EditUserDTO;
import com.building18.pojo.dto.UserDTO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from userinfo")
    List<User> selectUser();

    @Update("update userinfo set username=#{username},password=#{password},type=#{type},remarks=#{remarks},status=#{status} where id=#{id}")
    Integer updateUser(User user);

    @Delete("delete from userinfo where id=#{id}")
    Integer deleteUser(Integer id);

    @Select("select id, username, pic, type, remarks, status, create_time from userinfo where username=#{dto.username} and password=#{dto.password}")
    User login(@Param("dto") UserDTO dto);

    @Select("select id from sys_role_user where role_id=#{id}")
    List<Integer> beforeDeleteRole(Integer id);

    @Update("update userinfo set password=#{dto.newPassword} where id=#{dto.id} and password=#{dto.oldPassword}")
    Integer updateUserData(@Param("dto") EditUserDTO dto);
}
